<?php

namespace App\Models;

/**
 * App\Models\ArticleCategory
 *
 * @property int $id
 * @property string $name 类目名称
 * @property int $pid 上级分类ID
 * @property int $sort 类目排序
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory query()
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory wherePid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|ArticleCategory whereSort($value)
 * @mixin \Eloquent
 */
class ArticleCategory extends Base
{
    protected $table = 'article_categorys';

    protected $fillable = [
        'id','name','pid','sort'
    ];

    public $timestamps = false;//关闭自动维护


    /**
     * 获取列表
     * @return mixed
     */
    protected function getList($params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['kwd']) && $params['kwd']) {
                    $query ->where('name','like','%' . $params['kwd'] . '%');
                }
            })->orderBy('sort', 'desc')->paginate(config('app.limit'));
        return $lists;
    }

    protected function categorys(){
        $categorys = $this->select(['id','name'])->get()->toArray();
        return $categorys;
    }

}
